import axios from "axios"
import { Message } from "element-ui"
import { removeItem } from '@/utils/auth.js'
import router from '@/router'

const _axios = axios.create({
    baseURL: process.env.VUE_APP_URL
})

_axios.interceptors.request.use(config=>config, error=>Promise.reject(error))
_axios.interceptors.response.use(res=>res.data, error=>{
    if(error.response.data && error.response.data.message){
        Message.error(error.response.error.message)
    }
    if(error.response.status === 401){
        removeItem()
        $router.push('/login')
    }
})
